package br.com.cfccultura.admin.view.tag.combo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspException;

import org.springframework.stereotype.Component;

import br.com.cfccultura.admin.model.dao.IFuncionarioDAO;
import br.com.cfccultura.admin.model.vo.Funcionario;

@Component
public class ComboFuncionarioTag extends DefaultComboTag {
	
	private static final long serialVersionUID = 1073435506129686702L;
	
	private Boolean loginOnly = false;
	
	@Override
	public int doStartTagInternal() throws JspException {
		
		IFuncionarioDAO dao = getBean(IFuncionarioDAO.class);

		List<Funcionario> list = dao.consultar(new Funcionario());
		if(getLoginOnly()) {
			List<Funcionario> newList = new ArrayList<Funcionario>();
			for(Funcionario funcionario : list) {
				if(funcionario.getLogin() != null) {
					newList.add(funcionario);
				}
			}
			list.clear();
			list.addAll(newList);
		}
		buildCombo(list, "nome", "codigo");
		
		return SKIP_BODY;
	}
	
	public Boolean getLoginOnly() {
		return loginOnly;
	}
	public void setLoginOnly(Boolean loginOnly) {
		this.loginOnly = loginOnly;
	}
}
